<?php
Yii::import('application.widgets.chart.AbstractPieChart');

class CustomerGenderChart extends AbstractPieChart{

	public $title='Customers by Gender';

	protected function getData(){
		$criteria=new CDbCriteria();
		$criteria->select='gender , count(*) as count';
		$criteria->group='gender';
		$commandBuilder= Yii::app()->db->getSchema()->getCommandBuilder();
		$command=$commandBuilder->createFindCommand(Customer::model()->getTableSchema(),$criteria);
		$row=$command->queryAll();
		$result=array();
		foreach ($row as $teamRow){
			$result[]=array('value'=>intval($teamRow['count']),'name'=>DataUtil::getGender($teamRow['gender']));
		}
		return $result;
	}
}